@extends('admin.app')

<!-- @section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>业务管理</li>
            <li><a href="{{ admin_action('Business\OrganizationalUserManagementController@index') }}">机构用户管理</a></li>
            <li class="active">新增机构部门</li>
        </ol>
    </div>
@endsection -->

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
          投资经纪人
        </div>
        <div class="panel-body">
            <form class="form-horizontal form-validation"
                  action="{{ admin_action('Business\SalesStatisticsController@userToAgentSave') }}"
                  method="post">
                {{ csrf_field() }}	
                <label class="text-danger">*此操作会将投资人转换为经纪人</label>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">投资人:</label>
                    <div class="col-lg-4">
                    	<label class="text-danger control-label">{{ $user->userInfo->name }}</label>
                    	<input type="hidden" name="user_id" value="{{ $user->id }}">
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">机构:</label>
                    <div class="col-lg-4">
                        <select class="form-control org_yxjg" name="org_code" data-dept-url="{{ admin_action('Business\UsersController@orgDept') }}" data-rule-required="true">
                            <option value="">
                                请选择营销机构
                            </option>
                            @foreach($all_org as $org)
                                <option value="{{ $org->code }}">{{ $org->company_name }}({{ $org->description }})</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <label class="col-lg-2 control-label">归属部门:	</label>
                    <div class="col-lg-4">
                        <select class="form-control org_dept" data-rule-required='true' name='dept_code'>
                            <option value="">
                                请选择机构下属部门
                            </option>
                        </select>
                    </div>
                </div>
                <div class="line line-dashed b-b line-lg"></div>
                <div class="form-group">
                    <div class="col-lg-4 col-lg-offset-2">
                        <a href="javascript:history.back()"
                           class="btn btn-default">返&nbsp;回</a>
                        <button type="submit" class="btn btn-primary">提升为经纪人</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('scripts')
    <script type="text/javascript">
        $(function(){
            //动态查询营销机构的部门
            $('.org_yxjg').change(function(){
                $dept_url = $(this).data('dept-url');
                $org_code = $(this).find('option:selected').val();
                $('.org_dept').html("");
                //异步查询营销机构下级部门
                $.ajax({
                    url:$dept_url,
                    data:{org_code:$org_code},
                    success:function(data){
                        node = '';
                        if(data.length > 0){
                            for(var i in data){
                                    node = node+'<option value ='+data[i]["code"]+'>'+data[i]["name"]+'</option>';
                            }
                            $('.org_dept').append($(node));
                        }else{
                            node = node+'<option value ='+""+'>'+"  --  "+'</option>';
                            $('.org_dept').append($(node));
                        }
                    }
                });
            });
            $('.org_yxjg').trigger("change");
        });
    </script>
@endsection